package com.ukao.cashregister.ui.setting;


import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ukao.cashregister.R;
import com.ukao.cashregister.adapter.PrintAdapter;
import com.ukao.cashregister.base.BaseFragment;
import com.ukao.cashregister.bean.PrinterBean;
import com.ukao.cashregister.printer.PrinterHelper;
import com.ukao.cashregister.utils.CheckUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 扫码枪
 */
public class PrintRobFragment extends BaseFragment {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    Unbinder unbinder;

    @BindView(R.id.data)
    TextView data;
    @BindView(R.id.title)
    TextView title;



    private String mParam1;
    private String mParam2;

    private PrintAdapter PrintAdapter;
    private PrintAdapter mPrintAdapter;
    private String filePath;


    public static PrintRobFragment newInstance(String param1, String param2) {
        PrintRobFragment fragment = new PrintRobFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_setting_spear, container, false);
        unbinder = ButterKnife.bind(this, view);
        initView();
        initListener();
        return view;
    }

    @Override
    public void onSupportVisible() {
        super.onSupportVisible();



        List<PrinterBean> mData = PrinterHelper.getInstance().loadPrinterList();
        if (CheckUtils.isEmpty(mData)) {
            recyclerView.setVisibility(View.GONE);
            data.setVisibility(View.VISIBLE);

        } else {
            data.setVisibility(View.GONE);
            recyclerView.setVisibility(View.VISIBLE);
            mPrintAdapter.setDatas(mData);
        }

    }

    @Override
    protected void initView() {
        title.setText("打印机");
        List<PrinterBean> mPrinterBean = new ArrayList<>();
        initLinearRecyclerView(recyclerView);
        mPrintAdapter = new PrintAdapter(activity, mPrinterBean);
        recyclerView.setAdapter(mPrintAdapter);
    }

    @Override
    protected void initListener() {
        super.initListener();


    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }




}
